package com.bestcem.xm.ticket.entity.mongo;

import com.alibaba.fastjson.JSONObject;
import com.bestcem.xm.ticket.constant.ColumnConstant;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.List;

/**
 * 工单/预警 触发条件表
 * 和预警的规则合并了
 *
 * @author liheng
 * @version v1.0
 * @date 2021/8/16 10:19
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class TicketRule extends BaseEntity implements Serializable {

    private static final long serialVersionUID = -4098341141323752228L;
    /**
     * 问卷id
     */
    @JsonProperty(value = ColumnConstant.TicketRule.SURVEY_ID)
    private String surveyId;

    /**
     * 工单配置id
     */
    @JsonProperty(value = ColumnConstant.TicketRule.TICKET_CONFIG_ID)
    private String ticketConfigId;

    /**
     * 规则标题
     */
    @JsonProperty(value = ColumnConstant.TicketRule.TITLE)
    private String title;

    /**
     * 同一问卷内，规则id唯一
     */
    @JsonProperty(value = ColumnConstant.TicketRule.GID)
    private Integer gid;

    /**
     * 二次投放任务，工单完成或失败状态
     */
    @JsonProperty(value = ColumnConstant.TicketRule.OPERATION)
    private Integer operation;

    /**
     * 创建人
     */
    @JsonProperty(value = ColumnConstant.TicketRule.CREATOR)
    private String creator;

    /**
     * 版本号
     */
    @JsonProperty(value = ColumnConstant.TicketRule.VERSION)
    private Integer version;

    /**
     * 规则类型
     *
     * @see com.bestcem.xm.ticket.enums.TicketRuleTypeEnum
     */
    @JsonProperty(value = ColumnConstant.TicketRule.RULE_TYPE)
    private Integer type;

    /**
     * 工单生成条件
     * 字段类型，需要确认具体字段
     */
    @JsonProperty(value = ColumnConstant.TicketRule.CONDITION)
    private Condition condition;

    @JsonProperty(value = ColumnConstant.TicketRule.TARGET_LIST)
    private List<Target> targetList;

    /**
     * 是否sample
     */
    @JsonProperty(value = ColumnConstant.TicketRule.SAMPLE)
    private Boolean sample;

    /**
     * 生成条件列表
     * 没了
     */
    @JsonProperty(value = ColumnConstant.TicketRule.CONDITION_LIST)
    private List<Condition> conditionList;

    @Data
    public static class Condition implements Serializable {

        private static final long serialVersionUID = -9149967409648997250L;

        /**
         * 是否需要满足全部条件 | 0: 全部条件 | 1: 任意条件
         */
        @JsonProperty(value = ColumnConstant.TicketRule.Condition.LOGIC)
        private Integer logic;

        /**
         * 条件 or 条件组 信息
         */
        @JsonProperty(value = ColumnConstant.TicketRule.Condition.FILTERS)
        private List<JSONObject> filters;

        @JsonProperty(value = ColumnConstant.TicketRule.Condition.RTYPE)
        private Integer ruleType;

        private String rule;
    }

    @Data
    public static class Target implements Serializable {

        private static final long serialVersionUID = 5904015933101613528L;
        @JsonProperty(value = ColumnConstant.TicketRule.Target.LEVEL_ID)
        private String levelID;

        @JsonProperty(value = ColumnConstant.TicketRule.Target.ROLE_ID)
        private String roleID;

        @JsonProperty(value = ColumnConstant.TicketRule.Target.ROLE_OPTIONS)
        private List<RoleOption> roleOptions;

        @Data
        public static class RoleOption implements Serializable {

            private static final long serialVersionUID = 1573674303225952064L;

            @JsonProperty(value = ColumnConstant.TicketRule.Target.RoleOption.ID)
            private String id;
        }
    }
}
